package com.spring.arch.common.config;


import com.spring.arch.common.xss.XssFilter;
import com.spring.arch.common.xss.XssHttpServletRequestWrapper;
import com.spring.arch.common.xss.XssFilter;
import com.spring.arch.common.xss.XssHttpServletRequestWrapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;


/**
 * Filter配置
 *
 * @author Frank
 */
@Configuration
@ConditionalOnClass({XssFilter.class, XssHttpServletRequestWrapper.class})
@ConditionalOnProperty(prefix = "XSSFilter", value = "enable", matchIfMissing = true) // 允许使用
public class XSSFilterConfig {

    @Bean
    public FilterRegistrationBean<XssFilter> xssFilterRegistration() {
        FilterRegistrationBean<XssFilter> registration = new FilterRegistrationBean<XssFilter>();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new XssFilter());
        registration.addUrlPatterns("/*");
        registration.setName("xssFilter");
        registration.setOrder(Integer.MAX_VALUE);
        return registration;
    }
}